<?php
include("../bootstrap.php");

if (!empty($_SESSION['admin_id'])) {
	header('Location: admin_setup.php');
}
//--------------------------------
if (isset($_POST['Submit'])) {
	if (!empty($_POST['username']) && !empty($_POST['password'])) {
		$posted_username = $_POST['username'];
		$posted_password = $_POST['password'];
//		$q = $con->select_query("admin", "*", "where adminun  = '$un'");
		$admin = $my_db->select_row('SELECT * FROM admins WHERE username = ?', array($posted_username));

		if (!empty($admin)) {
			if (strcmp($posted_password, $admin['password']) !== 0) {
				$mess = getADMError("Invalid login credentials.");
			} else {
				// Good User
				$_SESSION['admin_id'] = $admin['id'];
				$_SESSION['admin_username'] = $admin['username'];
//				var_dump($_SESSION);exit;
				header("Location: admin_setup.php");
			}
		} else {
			$mess = getADMError("There is not such an admin in the system.");
		}
	} else {
		$mess = getADMError("You must enter administrator username/password.");
	}

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title><?php echo $title;?></title>

	<style type="text/css" media="all">
		@import url("css/style.css");
		@import url("css/jquery.wysiwyg.css");
		@import url("css/facebox.css");
		@import url("css/visualize.css");
		@import url("css/date_input.css");
	</style>

	<!--[if lt IE 8]>
	<style type="text/css" media="all">@import url("css/ie.css");</style><![endif]-->

</head>


<body>

<div id="hld">

	<div class="wrapper">        <!-- wrapper begins -->


		<div class="block small center login">

			<div class="block_head">
				<div class="bheadl"></div>
				<div class="bheadr"></div>

				<h2>TitleRate (Calc) - Admin Login</h2>
				<ul>
					<li></li>
				</ul>
			</div>
			<!-- .block_head ends -->


			<div class="block_content">

				<?php echo $mess; ?>

				<form action="login.php" method="POST" autocomplete="OFF">
					<p>
						<label>Username:</label> <br/>
						<input type="text" class="text" name="username" />
					</p>

					<p>
						<label>Password:</label> <br/>
						<input type="password" class="text" name="password" />
					</p>

					<p>
						<input name="Submit" type="submit" class="submit mid" value="Login"/><br/><br/>
						<small><a href="forgot.php">Forgot password ?</a></small>
					</p>
				</form>

			</div>
			<!-- .block_content ends -->

			<div class="bendl"></div>
			<div class="bendr"></div>

		</div>
		<!-- .login ends -->


	</div>
	<!-- wrapper ends -->

</div>
<!-- #hld ends -->


<!--[if IE]>
<script type="text/javascript" src="js/excanvas.js"></script><![endif]-->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.img.preload.js"></script>
<script type="text/javascript" src="js/jquery.filestyle.mini.js"></script>
<script type="text/javascript" src="js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="js/jquery.date_input.pack.js"></script>
<script type="text/javascript" src="js/facebox.js"></script>
<script type="text/javascript" src="js/jquery.visualize.js"></script>
<script type="text/javascript" src="js/jquery.visualize.tooltip.js"></script>
<script type="text/javascript" src="js/jquery.select_skin.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/ajaxupload.js"></script>
<script type="text/javascript" src="js/jquery.pngfix.js"></script>
<script type="text/javascript" src="js/custom.js"></script>


</body>
</html>
